#include<bits/stdc++.h>
using namespace std;
void solve(){
	int a,b,c;
	cin >> a >> b >> c;
	int ans = 0;
	ans += a;
	if(b % 3 == 1){
		if(c < 2){
			cout << -1 << "\n";
			return ;
		}
		ans += (b/3) + 1 + (c - 2) / 3;
		if((c - 2) % 3 != 0) ans++;
		cout << ans << "\n";
	}
	else if(b % 3 == 2){
		if(c < 1){
			cout << -1 << "\n";
			return ;
		}
		ans += (b/3) + 1 + (c - 1) / 3;
		if((c - 1) % 3 != 0) ans++;
		cout << ans << "\n";
	}else{
		ans += (b/3) + (c/3);
		if(c % 3 != 0) ans++;
		cout << ans << "\n";
	}
}
int main(){
	ios::sync_with_stdio(false),cin.tie(0);
	int t = 1;
	cin >> t;
	while(t--) solve();
}